package edu.humc.controller;

import edu.humc.pojo.Recycle;
import edu.humc.service.Impl.RecycleServiceImpl;
import edu.humc.service.RecycleService;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller("RecycleController")
public class RecycleController {
    @Resource(name = "RecycleServiceImpl")
    RecycleServiceImpl recycleService;
    @RequestMapping("/Recycle")
    public String SelectRecycleById(HttpSession session){
        int id=(int)session.getAttribute("id");
        List<Recycle> recycleList= recycleService.SelectRecycleById(id);
        session.setAttribute("recycleList",recycleList);
        return "/Recycle.jsp";
    }
    //    删除回收站内的内容
    @RequestMapping("/DeleteRecycleById")
    public String DeleteRecycleById(String mid, Model model){
        if (recycleService.DeleteRecycleById(mid)) {
            return "/Recycle.jsp";
        }
        model.addAttribute("OpeateErrorMessage","回收站删除错误！");
        return "/OpeateErrorPage.jsp";
    };
    @RequestMapping("/RecoverMessage")
    public String RecoverMessage(String mid,Model model){
        if (recycleService.RecoverMessage(mid)){
            return "/MessageList.jsp";
        }
        model.addAttribute("OpeateErrorMessage","回收站恢复留言错误！");
        return "/OpeateErrorPage.jsp";
    }
}
